package com.example.kaogong.sys.controller;


import com.example.kaogong.common.exception.ParamsErrorException;
import com.example.kaogong.common.utils.Assert;
import com.example.kaogong.common.utils.RespBean;
import com.example.kaogong.sys.pojo.CourseResource;
import com.example.kaogong.sys.pojo.CourseVideo;
import com.example.kaogong.sys.service.ICourseResourceService;
import com.example.kaogong.sys.service.ICourseVideoService;
import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 课程资料 前端控制器
 * </p>
 *
 * @author    
 * @since 2022-03-26
 */
@RestController
@RequestMapping("/course-resource")
@Api(tags = "课程资料接口")
@Slf4j
public class CourseResourceController {
    @Autowired
    private ICourseResourceService courseResourceService;

    @ApiOperation(value = "新增课程资料")
    @PostMapping("")
    public RespBean addCourseResource(@Valid @RequestBody CourseResource courseResource) {
        log.info("request:{}", new Gson().toJson(courseResource));
        RespBean respBean = courseResourceService.addCourseResource(courseResource);
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }

    @ApiOperation(value = "根据资料编号删除课程资料")
    @DeleteMapping("/{resourceId}")
    public RespBean deleteCourseResource(@PathVariable Integer resourceId) {
        Assert.notNull(resourceId, new ParamsErrorException("资料编号不能为空"));
        RespBean respBean = courseResourceService.deleteCourseResource(resourceId);
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }
}
